package threads;

import java.util.Stack;

public class Producer extends MyThread implements MyThreadsOperations {
	
	private int index = 0;

	public Producer(String name,Stack<Integer> mBox, long cycle) {
		super(name);
		setThreadOperations(this);
		localMBox = mBox;
		cycleLength_msec = cycle;
	}
	
//	public void run(){
//		boolean running = true;
//		while(running){
//			try {
//				sleep(cycleLength_msec);
//				produce();
//			} catch (InterruptedException e) {
////				e.printStackTrace();
//				running = false;
//				System.out.println(getName()+ "I'm interrupted");
//			}
//		}
//	}
	
	public void produce(){
		Integer prod = new Integer(index);
		localMBox.push(prod);
		System.out.println(getName()+" produced "+prod.intValue());
		index++;
	}

	@Override
	public void threadOperations() throws InterruptedException {
		produce();		
	}


}
